package com.example.demo;

import org.springframework.stereotype.Component;



import java.io.IOException;


import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;


@Component
@WebFilter(filterName = "myFilter", urlPatterns = "/*")
public class DemoFilter implements Filter {
    static int count = 1;
    @Override
    public void init(FilterConfig filterconfig) throws ServletException {
        // TODO Auto-generated method stub

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        /*
        System.out.println("------------------过滤器开始:"+count+"------------");
        //通过request获取信息
        System.out.println(request.getLocalAddr());
        System.out.println("------------------过滤器结束:"+count+"------------");
        count+=1;*/
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {
        // TODO Auto-generated method stub

    }
}

